#include "reminds.h"
#include "ui_reminds.h"
#include "reservehome.h"
#include "QMessageBox"
#include<QMouseEvent>
bool reminds::isFromHome = false;

reminds::reminds(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::reminds)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint); // 设置窗口无边框
    if(isFromHome){
        ui->checkBox->hide();
    }
}

reminds::~reminds()
{
    delete ui;
}

void reminds::on_pushButton_clicked()
{
    if(!reminds::isFromHome){
        this->close();
        if(!reserveHome::isRemindShowAgain){
            // 创建一个QMessageBox对象
            QMessageBox messageBox;
            messageBox.setWindowTitle("提示");
            messageBox.setText("您可在主页“我的”中查看座位预约规则");
            // 设置消息类型
            messageBox.setIcon(QMessageBox:: Information);
            // 添加按钮并设置点击事件处理函数
            QPushButton *okButton = messageBox.addButton(QMessageBox::Ok);
            // 为“Ok”按钮设置点击事件处理函数
            connect(okButton, &QPushButton::clicked, [&]() {
                reserveHome*r = new reserveHome;
                r->show();
            });
            // 显示消息框
            messageBox.exec();
        }else{
            reserveHome*r = new reserveHome;
            r->show();
        }
    }else{
        this->close();
    }
}

void reminds::on_checkBox_stateChanged(int arg1)
{
    if (arg1 == Qt::Checked) {
        // 用户勾选了复选框，执行相应的操作
        reserveHome::isRemindShowAgain = false;
    } else {
        // 用户取消了勾选
        reserveHome::isRemindShowAgain = true;
    }
}

void reminds::mousePressEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton) {
                initialMousePosition = event->globalPos(); // 记录鼠标按下时的全局位置
                isDragging = true; // 开始拖动
            }
    }

void reminds::mouseMoveEvent(QMouseEvent *event){
    if (isDragging && event->buttons() & Qt::LeftButton) {
                QPoint delta = event->globalPos() - initialMousePosition; // 计算鼠标移动的距离
                move(x() + delta.x(), y() + delta.y()); // 根据鼠标移动的距离来移动窗口
                initialMousePosition = event->globalPos(); // 更新鼠标位置
            }
    }
void reminds::mouseReleaseEvent(QMouseEvent *event) {
        if (event->button() == Qt::LeftButton) {
            isDragging = false; // 结束拖动
        }
    }

